//二叉树的前序遍历，非递归方式
class Solution {
public:
    vector<int> preorderTraversal(TreeNode* root) {
        vector<int> v;
        TreeNode* cur = root;
        stack<TreeNode*> st;
        while(cur || !st.empty())
        {
            //分为两步遍历
            //1、遍历左子树
            //2、遍历压进栈的右子树
            while(cur)
            {
                v.push_back(cur->val);
                st.push(cur);
                cur=cur->left;
            }
            TreeNode* top = st.top();
            st.pop();
            cur=top->right;
        }
        return v;

    }
};

//二叉树的中序遍历，非递归方式
class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {

        vector<int> v;
        TreeNode* cur = root;
        stack<TreeNode*> st;
        while(cur || !st.empty())
        {
            //分为两步遍历
            //1、遍历左子树
            //2、遍历压进栈的右子树
            while(cur)
            {
                st.push(cur);
                cur=cur->left;
            }
            //左路节点右子树
            TreeNode* top = st.top();
            v.push_back(top->val);
            st.pop();
            //循环子问题访问右子树
            cur=top->right;
        }
        return v;
    }
};


//根据二叉树的前序和中序，构建树
class Solution {
public:
    TreeNode* _buildTree(vector<int>& preorder, vector<int>& inorder,int& prei,int inbegin,int inend)
    {
        if(inbegin>inend)
        {
            return nullptr;
        }
        int rooti = inbegin;
        //找到根节点在inorder中的位置
        while(rooti <= inend)
        {
            if(inorder[rooti]==preorder[prei])
                break;
            ++rooti;
        }
        TreeNode* root = new TreeNode(preorder[prei++]); //建立根
        //[左子树] i [右子树]
        //[inbegin,i-1] i [i+1,inend]
        root->left = _buildTree(preorder,inorder,prei,inbegin,rooti-1);
        root->right = _buildTree(preorder,inorder,prei,rooti+1,inend);
        return root;
    } 
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
        int prei=0;
        return _buildTree(preorder,inorder,prei,0,inorder.size()-1);        

    }
};

//根据二叉树的中序和后序，构建树
class Solution {
public:
    TreeNode* _buildTree(vector<int>& inorder, vector<int>& postorder,int& prei,int inbegin,int inend)
    {
        if(inbegin>inend)
        {
            return nullptr;
        }
        //从后往前遍历
        int rooti = inbegin;
        while(rooti<=inend)
        {
            if(inorder[rooti]==postorder[prei])
                break;
            ++rooti;
        }

        TreeNode* root = new TreeNode(postorder[prei--]);
        root->right = _buildTree(inorder,postorder,prei,rooti+1,inend);
        root->left = _buildTree(inorder,postorder,prei,inbegin,rooti-1);
        return root;
    }
    TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
        int prei = inorder.size()-1;
        return _buildTree(inorder,postorder,prei,0,inorder.size()-1);
    }
}; 










//牛客 进制的转换
int main() {
    string s, table = "0123456789ABCDEF";
    int m, n;
    cin >> m >> n;
    bool flag = false;
// 如果是负数，则转成正数，并标记一下
    if (m < 0) {
        m = 0 - m;
        flag = true;
    }
    if(m==0)
    {
        s+=table[0];
    }
// 按进制换算成对应的字符添加到s
    while (m) {
        s += table[m % n];
        m /= n;
    }
    if (flag)
        s += '-';
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}



//牛客  计算糖果
int main() {
        int num[4]={0};
        for(int i=0;i<4;++i)
        {
            cin>>num[i];
        }
        float a = (num[0]+num[2])/2.0;
        float b = num[2]-a;
        float c = num[3]-b;
        if(int(a)!=a && int(b)!=b && int(c)!=c)
        {
            cout<<"No"<<endl;
        }
        else if(a<0 || b<0 ||c<0)
        {
            cout<<"No"<<endl;
        }
        else
            cout<<a<<" "<<b<<" "<<c<<endl;
        return 0;
    
}

//牛客数组中出现一般的数
class Solution {
public:
    int MoreThanHalfNum_Solution(vector<int> numbers) {
        if(numbers.empty())
            return 0;
        sort(numbers.begin(),numbers.end());
        //排序后，位于中间位置的就是众数
        int i=numbers.size()/2;
        return numbers[i];
    }
};